//
//  UserAccountModel.swift
//  weibobbaj
//
//  Created by Tiffany宝 on 16/4/19.
//  Copyright © 2016年 Tiffany. All rights reserved.
//

import UIKit
/*
{
"access_token" : "2.00J1338GOCWDFD53a90e1984GZvx9E",
"expires_in" : 157679999,
"remind_in" : 157679999,
"uid" : 5901087097,
}
{
"access_token": "ACCESS_TOKEN",
"expires_in": 1234,
"remind_in":"798114",
"uid":"12341234"
}
*/
class UserAccountModel: NSObject,NSCoding {
    
    
    var uid: String?
    
    var expires_in: NSTimeInterval = 0{
        
        didSet{
           expires_time = NSDate(timeIntervalSinceNow: expires_in)
        }
    }
    
    // 过期时间 ： 当accessToken获取回来的那一刻开始算起， expires_in 秒后的时间
    var expires_time: NSDate?
    
    var access_token: String?
    
    var remind_in: String?
    
    
    //    var uid: Int = 0
    //
    //    var expires_in: Int = 0
    //
    //    var access_token: String?
    //
    //    var remind_in: Int = 0
    
    var name: String?
    
    var avatar_large: String?
    
    //KVC
    init(dic:[String : AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dic)
    }
    
    //归档
    func encodeWithCoder(encoder: NSCoder) {
        
        encoder.encodeDouble(expires_in, forKey: "expires_in")
        encoder.encodeObject(uid, forKey: "uid")
        encoder.encodeObject(access_token, forKey: "access_token")
        encoder.encodeObject(remind_in, forKey: "remind_in")
        encoder.encodeObject(name, forKey: "name")
        encoder.encodeObject(avatar_large, forKey: "avatar_large")
        //存储过期时间
        encoder.encodeObject(expires_time, forKey: "expires_time")
    }
    
    //解档
    required init?(coder decoder: NSCoder) {
        
        expires_in = decoder.decodeDoubleForKey("expires_in")
        uid = decoder.decodeObjectForKey("uid") as? String
        access_token = decoder.decodeObjectForKey("access_token") as? String
        remind_in = decoder.decodeObjectForKey("remind_in") as? String
        name = decoder.decodeObjectForKey("name") as? String
        avatar_large = decoder.decodeObjectForKey("avatar_large") as? String
        //取出过期时间
        expires_time = decoder.decodeObjectForKey("expires_time") as? NSDate
        
    }
    
}


